package com.hhs.storage.controller;

import com.hhs.storage.bean.ResponseInfo;
import com.hhs.storage.service.BaseLogsService;
import com.hhs.storage.service.BaseUserService;
import com.hhs.storage.util.NumberUtil;
import com.hhs.storage.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Map;

@Controller
@Slf4j
public class LoginController {

    @Resource
    private BaseLogsService baseLogsService;
    @Resource
    BaseUserService userService;
    @RequestMapping("oauth")
    @ResponseBody
    public Map oauth(String account, String password){
        System.out.println(password+"==========="+account);
            if(StringUtils.isEmpty(account) ||StringUtils.isEmpty(password) )
                return ResponseInfo.error("请输入参数");
            else
             return userService.oauth(account,password);
    }

    @RequestMapping("checkLogin")
    @ResponseBody
    public Map checkLogin(){
            return ResponseInfo.success();
    }

    @RequestMapping("checkUser")
    @ResponseBody
    public Map checkL(String account){
        if(StringUtils.isEmpty(account) )
            return ResponseInfo.error("请输入参数");
        else
            return userService.checkUser(account);
    }

    @RequestMapping("fastRegist")
    @ResponseBody
    public Map fastRegist(String account,String sqm,int type){
        if(StringUtils.isEmpty(account) )
            return ResponseInfo.error("请输入参数");
        else{
            Map map = userService.fastRegist(account, sqm, type);
            if(NumberUtil.toIntCase(StringUtil.zNull(map.get("code")))==1){
                return  userService.oauth(account,"123456");
            }else{
                return ResponseInfo.error(map.get("msg").toString());
            }
        }
    }
}
